package com.up.management.controller;

import com.up.common.annotation.Log;
import com.up.common.core.controller.BaseController;
import com.up.common.core.domain.AjaxResult;
import com.up.common.core.page.TableDataInfo;
import com.up.common.enums.BusinessType;
import com.up.common.utils.poi.ExcelUtil;
import com.up.management.domain.entity.Inheritor;
import com.up.management.service.IInheritorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 传承人管理Controller
 * 
 * @author cloud
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/management/inheritor")
public class InheritorController extends BaseController
{
    @Autowired
    private IInheritorService inheritorService;

    /**
     * 查询传承人管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:inheritor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Inheritor inheritor)
    {
        startPage();
        List<Inheritor> list = inheritorService.selectInheritorList(inheritor);
        return getDataTable(list);
    }

    /**
     * 导出传承人管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:inheritor:export')")
    @Log(title = "传承人管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Inheritor inheritor)
    {
        List<Inheritor> list = inheritorService.selectInheritorList(inheritor);
        ExcelUtil<Inheritor> util = new ExcelUtil<Inheritor>(Inheritor.class);
        util.exportExcel(response, list, "传承人管理数据");
    }

    /**
     * 获取传承人管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:inheritor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inheritorService.selectInheritorById(id));
    }

    /**
     * 新增传承人管理
     */
    @PreAuthorize("@ss.hasPermi('management:inheritor:add')")
    @Log(title = "传承人管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Inheritor inheritor)
    {
        return toAjax(inheritorService.insertInheritor(inheritor));
    }

    /**
     * 修改传承人管理
     */
    @PreAuthorize("@ss.hasPermi('management:inheritor:edit')")
    @Log(title = "传承人管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Inheritor inheritor)
    {
        return toAjax(inheritorService.updateInheritor(inheritor));
    }

    /**
     * 删除传承人管理
     */
    @PreAuthorize("@ss.hasPermi('management:inheritor:remove')")
    @Log(title = "传承人管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inheritorService.deleteInheritorByIds(ids));
    }
}
